﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Components;
using System.Configuration;
using System.IO;
using System.Drawing;
namespace JQueryUploadDemo
{
    /// <summary>
    /// DeleteHander 的摘要说明
    /// </summary>
    public class DeleteHander : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";            
            string qid = context.Request.QueryString["q"] ?? "";
            string name = context.Request.QueryString["n"] ?? "";
            try
            {
                if (!string.IsNullOrEmpty(qid) && !string.IsNullOrEmpty(name))
                {
                    //UploadPic.DelPic(string.Format("{0}", name));
                    //UploadPic.DelPic(string.Format("{0}", name));
                    //UploadPic.DelPic(string.Format("{0}", name));
                    DelPic(name);
                    context.Response.Write(qid);
                }
                else
                {
                    context.Response.Write("0");
                }                
            }
            catch { context.Response.Write("0"); }
            
        }
        public static void DelPic(string PicPath)
        {
            string FilePath = string.Format(@"{0}\{1}\{2}", StrHelp.GetPhysicalPath(), ConfigurationManager.AppSettings["UploadPath"], PicPath);

            if (File.Exists(FilePath))
            {
                FileInfo delFile = new FileInfo(FilePath);
                try
                {
                    delFile.Delete();
                }
                catch (Exception e)
                {
                    throw new ApplicationException(e.Message);
                }
            }
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}